var vrv = vrv || {};
vrv.sentiment = vrv.sentiment || {};

/** 舆情首页*/
vrv.sentiment.index = {
	init: function(){
		this.btn.init();
		this.page.getIndex();
	},
	
	page:{
		init: function(){
			this.getIndex();
		},
		
		getIndex: function(){
			var userToken = $('#userTonken').val();
			var action= 'sentiment/toIndex.do?userToken='+userToken;
			base.AJAX_POST(action, null, 'html', function(html){
				$('.sentiment>.content').empty().append($(html));
				
			});
		}
		
	},
	
	btn: {
		init: function(){
			this.searchBtn();
			this.searchDown();
			this.setBtn();
			this.exponentBtn();
			this.toListBtn();
			this.toDesc();
		},
		
		/** 查询按钮*/
		searchBtn: function(){
			$('.search>i').click(function(){
				vrv.Mask.init($('body'));
				var keyWord = $('#search').val();
				var userToken = $('#userTonken').val();
				var action = 'sentiment/toList.do?userToken='+userToken + '&keyWord=' + keyWord;
				base.getAction(action);
			});
		},
		
		//搜索下拉
		searchDown:function(){
			
			//聚焦
			$("#search").on("focusin",function(){
				// 清除之前的关键词
				$(".wj-search-list").empty();
				
				// 拼接关键词组
				$('.modal-body2 .vrv').each(function(index,item){
					var key = $(item).text();
					var li = '<li data-key="'+key+'">'+key+'</li>';
					$(".wj-search-list").append(li);
				});
				
				if($(".wj-search-list").size()!=0){
					$(".wj-search-list").slideDown("fast");
				}
			});
			
			//失去焦点
			$("#search").on("blur",function(){
				$(".wj-search-list").slideUp("fast");
			});
			
			// 列表点击事件
			$(".wj-search-list").on("click","li",function(){
				var inputVal =  $("#search").val();
				var data = $(this).attr("data-key");
				$("#search").val(inputVal+" "+data);
				$(this).parents("ul.wj-search-list").slideUp("fast");
				$('.search>i').click();
			});
		},
		
		/** 设置关键字*/
		setBtn: function(){
			/*$('.set').click(function(){
				var userToken = $('#userTonken').val();
				var action = 'sentiment/toSetUp.do?userToken='+userToken;
				base.getAction(action);
			});*/
			
			/*设置关键字-th*/
			$('.set').on('click', function(){
				$('#myModal2').modal('show');
				var  keyNumber = 10 - $('.modal-body2 div').size();
				if(keyNumber >= 0 ){
					$('.add_keywords>p').html(messages.validKeyWordLeft + keyNumber).css({"color":"#333"});
				}else{
					$('.add_keywords>p').html(messages.validKeyWordIsMax).css({"color":"#E56154"});
				 }
			   });
			//点击输入框后的“对号”按钮实现增加关键字功能
			$('.modal-header2 #modal_text img').on('click', function(){
				var t = $('.modal-body2 div').size();
				var keyNumber = 9 - t;
				var k_text = $('.sub_text').val();
				if (k_text=="" || k_text==null){
					Message.showMessage({
						text: messages.inputKeyWord,
					});
					return false;
				}
				//输入关键字内容只能输入汉字、数字、字母
				var reg = /[^/0-9a-zA-Z\u4E00-\u9FA5\s]/g; 
				if(reg.test(k_text)){
					Message.showMessage({
						text: messages.validKeyWordIsCharacters,
					});
					return false;
				}
				if(keyNumber >= 0 ){
					$('.modal-body2').append('<div class="add_kws"><span class="vrv">' + k_text + '</span><span class="x">' + 'X' + '</span></div>');
					$('.add_keywords>p').html(messages.validKeyWordLeft + keyNumber);
				}else{
					$('.add_keywords>p').html(messages.validKeyWordIsMax).css({"color":"#E56154"});
				 }
//				$('.modal-header2 .sub_text').val("").focus();
				$('.modal-header2 .sub_text').val("").blur();
			 });
			//点击“X”号按钮实现删除关键字功能
			$('.modal-body2').delegate('.x','click', function(){
				var key_Num = 11 - $('.modal-body2 div').size();
				$(this).parent().remove();
				if(key_Num < 0){
					$('.add_keywords>p').html(messages.validKeyWordIsMax).css({"color":"#E56154"});
				}else{
					$('.add_keywords>p').html(messages.validKeyWordLeft + key_Num).css({"color":"#333"});
				   }
			   });	
			//点击取消按钮弹框消失
			$(".modal-footer2 .cancel").on('click', function(){
				$('#myModal2').modal('hide');
				$('.modal-body2 .add_kws').remove();
		    });
			
			
			$('.content').delegate('#keyWordIsNull', 'click', function(){
				/*var userToken = $('#userTonken').val();
				var action = 'sentiment/toSetUp.do?userToken='+userToken;
				base.getAction(action);*/
				$('.set').click();
			});
		},
		
		/** 指数事件*/
		exponentBtn: function(){
			$('.news-title-bar').delegate('.exponent', 'click', function(){
				var userToken = $('#userTonken').val();
				var action = 'sentiment/toCountChat.do?userToken='+userToken;
				base.getAction(action);
			});
		},
		/** 更多按钮*/
		toListBtn: function(){
			$('.content').delegate('.toList', 'click', function(){
				var userToken = $('#userTonken').val();
				var action = 'sentiment/toList.do?userToken='+userToken;
				base.getAction(action);
			});
		},
		
		/** 查询详情*/
		toDesc: function(){
			$('.content').delegate('.listInfo>ul>li', 'click', function(){
				var pid = $(this).attr('pid');
				var userToken = $('#userTonken').val();
				var action = 'sentiment/toDesc.do?userToken='+userToken +'&pid='+pid;
				base.getAction(action);
			});
		}
		
	}
},

/** 关键字设置页面*/
vrv.sentiment.setUp = {
		/**
		 * 
		 */
/*	htmlTmep:{
		keyWord:'<div class="setInfo">'+
				    '<div class="title">'+
				       '<span>'+messages.set+':</span>'+
					   '<div><input type="text" id="kwsgroupName" placeholder="'+messages.inputKeyWordName+'"/></div>'+
					   '<span class="del_w"><i class="fa fa-remove"></i></span>'+
	                '</div>'+
		            '<div class="keywords"><ul>{0}</ul></div>'+
		            '<div class="radio_w">'+
		                '<ul class="answer">'+
		                    '<li><input id="answer-{1}0" type="radio" name="answer-{1}" hidden="hidden" checked="checked" value="0"><label for="answer-{1}0">'+messages.add+'</label></li>'+
					        '<li><input id="answer-{1}1" type="radio" name="answer-{1}" hidden="hidden"><label for="answer-{1}1" value="1">'+messages.or+'</label></li>'+
					    '</ul>'+
					'</div>'+
					'<div class="keywords"><ul>{2}</ul></div>'+
				'</div>',
				
		liTemp1:'<li><div><input type="text" name="kwsmodel1" placeholder="'+messages.inputKeyWord+'" /></div></li>',
		liTemp2:'<li><div><input type="text" name="kwsmodel2" placeholder="'+messages.inputKeyWord+'" /></div></li>'
	},*/
	
	keyWord:{
		
		obj:{
			modelnum:'',
			kwsgroupName:'',
			kwsrelationship:'',
			kwsmodel1:'',
			kwsmodel2:'',
		},
		
		set: function(opt){
			this.obj.modelnum = opt.modelnum;
			this.obj.kwsgroupName= opt.kwsgroupName;
			this.obj.kwsrelationship= opt.kwsrelationship;
			this.obj.kwsmodel1= opt.kwsmodel1;
			this.obj.kwsmodel2= opt.kwsmodel2;
		},
	
		empty:function(){
			this.obj.modelnum='';
			this.obj.kwsgroupName='';
			this.obj.kwsrelationship='';
			this.obj.kwsmodel1='';
			this.obj.kwsmodel2='';
		},
		get:function(){
			
			var str = "{'modelnum':'{0}','kwsgroupName':'{1}','kwsrelationship':'{2}','kwsmodel1':'{3}','kwsmodel2':'{4}'}";
			
			str = str.format([this.obj.modelnum,
			                  this.obj.kwsgroupName,
			                  this.obj.kwsrelationship,
								this.obj.kwsmodel1
								,this.obj.kwsmodel2]);
			return str;
		}
		
	},
	
	init: function(){
		this.btn.init();
	},
	
	page:{
		init: function(){
			
		}
	},
	
	btn: {
		init: function(){
			/*this.delSetBtn();
			this.addKeyWordBtn();
			this.subKeyWordBtn();*/
			this.confirmBtn();
		},
	/*	delSetBtn: function(){
			$('.keywordSet').delegate('.del_w', 'click', function(){
				var _this = $(this);
				var $thisParents = _this.parents('.setInfo');
				var index = $('.setInfo').size();
				
				if (index <= 1){
					$thisParents.find('input[type=text]').val('');
				}else{
					$thisParents.slideUp("normal",function(){
						   $(this).remove();
					 });
				}
			});
		},*/
	/*	addKeyWordBtn:function(){
			$('.addKeyWord').click(function(){
				var setInfoSize = $('.setInfo').size();
				
				if (setInfoSize > 4){
					Message.showMessage({
						text: messages.validKeyWordIsBigNum,
					});
					return;
				}
				var li1 = '';
				var li2 = '';
				var liTemp1 = vrv.sentiment.setUp.htmlTmep.liTemp1;
				var liTemp2 = vrv.sentiment.setUp.htmlTmep.liTemp2;
				
				var index  = (new Date()).valueOf();
				for (var i=0; i<6; i++){
					li1 += liTemp1;
					li2 += liTemp2;
				}
				var $keyWords = $(vrv.sentiment.setUp.htmlTmep.keyWord.format([li1, index, li2]));
				
				$(this).before($keyWords);
				$keyWords.slideDown();
			});
		},*/
		confirmBtn: function(){
			$('.modal-footer2 .confirm').click(function(){
				var self = $(this);
				var keyWordList = ""
				var divNum = $('.modal-body2 div').size();
				var isTrue = false;
				if(divNum <= 0){
					Message.showMessage({
						text: messages.inputKeyWord,
					});
					return false;
				}
				$('.modal-body2 div').removeClass("add_kws");
				//只能输入汉字、数字、字母,即特殊字符校验
				/*var reg = /[^/0-9a-zA-Z\u4E00-\u9FA5\s]/g;
				if (self.hasClass('nosub')){
					return
				}
				self.addClass('nosub').find('i').removeClass().addClass('fa fa-spinner fa-spin');*/
				$('.modal-body2').each(function(i, v){
					var kwsgroupName ="";
					var kwsrelationship = 0;
					var kwsmodel1 = "";
					var kwsmodel2 = "";
				$('.modal-body2 .vrv').each(function(index,item){
					var val = $(item).text();
					//console.log(item);
					if (val){
						index==0?kwsmodel1 += val:kwsmodel1 += ","+val;
					}
				})
					/*if(reg.test(kwsgroupName)){
						Message.showMessage({
							text: messages.validKeyWordIsNameCharacters,
						}); 
						isTrue = true;
						return false;
					}
					$(this).find('input[name=kwsmodel1]').each(function(){
						var val = $(this).val();
						if(reg.test(val)){
							Message.showMessage({
								text: messages.validKeyWordIsCharacters,
							});
							isTrue = true;
							return false;
						}
						if (val){
							kwsmodel1 += val+",";
						}
					});*/
					//跳出大循环
					/*if(isTrue) {
						self.removeClass('nosub').find('i').removeClass().addClass('fa fa-cloud-upload');
						return false;
					}
					$(this).find('input[name=kwsmodel2]').each(function(){
					    var val = $(this).val();

						if(reg.test(val)){
							Message.showMessage({
								text: messages.validKeyWordIsCharacters,
							});
							isTrue = true;
							return false;
						}
					    if (val){
					    	kwsmodel2 += val+",";
					    }
					});*/
					//跳出大循环
					/*if(isTrue) {
						self.removeClass('nosub').find('i').removeClass().addClass('fa fa-cloud-upload');
						return false;
					}
					kwsmodel1 = kwsmodel1.substring(0, kwsmodel1.length-1);
					kwsmodel2 = kwsmodel2.substring(0, kwsmodel2.length-1);
					
					if($.trim(kwsgroupName).length == 0 || ($.trim(kwsmodel1).length == 0 && $.trim(kwsmodel2).length == 0)){
						Message.showMessage({
							text: messages.validKeyWordIsNull,
						});						
						isTrue = true;
						return false;
					}*/
					vrv.sentiment.setUp.keyWord.set({
						modelnum:1,
						kwsgroupName:"明星",
						kwsrelationship:0,
						kwsmodel1:kwsmodel1,
						kwsmodel2:"",
					});
					keyWordList = keyWordList + vrv.sentiment.setUp.keyWord.get() + ','
				});
				//退出函数体
				/*if(isTrue){
					self.removeClass('nosub').find('i').removeClass().addClass('fa fa-cloud-upload');
					return;
				}*/
				keyWordList ="["+ keyWordList.substring(0,keyWordList.length-1)+"]";
				var data = {
						keyWordList:keyWordList,
						userToken:localStorage.getItem("userTonken")
				};
//				console.log(data);
				var action = "sentiment/saveKeyWord.do"
				base.AJAX_POST(action, data, 'json', function(o){
//					self.removeClass('nosub').find('i').removeClass().addClass('fa fa-cloud-upload');
					if (o.chat.resCode == "10000"){
						Message.showMessage({
							text: messages.setUp_success,
							callFn: function(){
								vrv.sentiment.index.page.getIndex();
								$('#myModal2').modal('hide');
							}
						});
					}else{
						Message.showMessage({
							text: messages.setUp_fail,
						});	
					}
				});
				
			});
		}
		
	}
}


/** 滑动加载*/
vrv.pm = vrv.pm || {};
vrv.pm.scrollcust={
	myScroll : {},
	init : function(){
		this.myScroll = new IScroll('#wrapper', { probeType: 3, mouseWheel: true ,click:true}) || {};
	},
	
	myScrollref: function(){
		this.myScroll.refresh();
	},
	myIScroll : function(opt) {
		//var myScroll,
		upIcon = $("#up-icon"),
		downIcon = $("#down-icon");
		
		
		
		this.myScroll.on("scroll",function(){
			var y = this.y,
				maxY = this.maxScrollY - y,
				downHasClass = downIcon.hasClass("reverse_icon"),
				upHasClass = upIcon.hasClass("reverse_icon");
			
			if(y >= 40){
				!downHasClass && downIcon.addClass("reverse_icon");
				return "";
			}else if(y < 40 && y > 0){
				downHasClass && downIcon.removeClass("reverse_icon");
				return "";
			}
			
			if(maxY >= 40){
				!upHasClass && upIcon.addClass("reverse_icon");
				return "";
			}else if(maxY < 40 && maxY >=0){
				upHasClass && upIcon.removeClass("reverse_icon");
				return "";
			}
		});
		
		this.myScroll.on("slideDown",function(){
			if(this.y > 40){
				opt.slideUp();
				this.myScroll.refresh();
			}
		});
		
		this.myScroll.on("slideUp",function(){
			if(this.maxScrollY - this.y > 40){
				opt.slideDown();
				//myScroll.refresh();
			}
		});
	}	
}

/** 列表页面*/
vrv.sentiment.list = {
	
	init: function(){
		this.btn.init();
		this.page.init();
	},
	
	commonFn:{
		/** 获取列表信息*/
		getListInfo:function(opt){
			opt = opt || {};
			var data = opt.data || {};
			var fnCall = opt.fnCall || function(o){
				$('.sentimentList>ul').empty().append(o);
			};
			var action = "sentiment/addList.do";
			vrv.Mask.init($('body'));
			base.AJAX_POST(action, data, "html", function(html){
				var $html = $(html);
				fnCall($html);
				vrv.Mask.close();
				vrv.pm.scrollcust.myScrollref();
			});
		},
		
	},
	
	page:{
		
		init: function(){
			this.loadList();
		},
		
		loadList:function(){
			var size = 20;
			var pageNum = 1;
			var flag = false;
			vrv.pm.scrollcust.init();
			vrv.pm.scrollcust.myIScroll({
				slideDown:function(){
					
					if (flag){
						return;
					}
					pageNum ++;
					
					var keyWord = "_";
					var xkeyWord = $.trim($('#search').val());
					
					var s = xkeyWord.split(" ");
					var ss = "";
					for(var i = 0; i<s.length; i++){
						
						if (s[i]){
							ss = ss + s[i] + "_";
						}
					}
					keyWord =  keyWord + ss 
					var userToken = localStorage.getItem("userTonken");
					var opt = {
						data : {
							pageNum:pageNum,
							pageSize:size,
							keyWord:keyWord,
							userToken:userToken
						},
						
						fnCall: function(html){
							
							if ($(html).size() < size){
								flag = true;
							}
							$('.sentimentList>ul').append(html);
						}
					};
					vrv.sentiment.list.commonFn.getListInfo(opt);
					$("#up-icon").removeClass("reverse_icon");
				},
				
				slideUp: function(i){
					var keyWord = "_";
					var xkeyWord = $.trim($('#search').val());
					
					var s = xkeyWord.split(" ");
					var ss = "";
					for(var i = 0; i<s.length; i++){
						
						if (s[i]){
							ss = ss + s[i] + "_";
						}
					}
					keyWord =  keyWord + ss 
					var userToken = localStorage.getItem("userTonken");
					var opt = {
						data : {
							pageNum:1,
							pageSize:size,
							keyWord:keyWord,
							userToken:userToken
						}
					};
					vrv.sentiment.list.commonFn.getListInfo(opt);
					 $("#down-icon").removeClass("reverse_icon");
					
				}
				
			});
		}
	},
	
	btn: {
		init: function(){
			this.toDesc();
			this.toSearch();
			this.searchDown();
		},
		
		//搜索下拉
		searchDown:function(){
			//聚焦
			$("#search").on("focusin",function(){
				if($(".wj-search-list").size()!=0){
					$(".wj-search-list").slideDown("fast");
				}
			});
			
			//失去焦点
			$("#search").on("blur",function(){
				$(".wj-search-list").slideUp("fast");
			});
			
			// 列表点击事件
			$(".wj-search-list>li").on("click",function(){
				var inputVal =  $("#search").val();
				var data = $(this).attr("data-key");
				$("#search").val(inputVal+" "+data);
				$(this).parents("ul.wj-search-list").slideUp("fast");
				$('.fa-search').click();
			});
		},
		
		/**列表搜索栏*/
		toSearch: function(){
			$('.fa-search').click(function() {
				vrv.Mask.init($('body'));
				var keyWord = $.trim($('#search').val());
				
				var userToken = $('#userTonken').val();
				/*$('#keyWord').val(keyWord);*/

				var action = 'sentiment/toList.do?userToken='+userToken + '&keyWord=' + keyWord;
				base.getAction(action);

			});
			
		},
		
		/** 查询详情*/
		toDesc: function(){
			/*$('body').delegate('.sentimentList>ul>li', 'touchstart', function(){
				var _this = $(this);
				touchFunc($(this).get(0), 'click', function(){
					var pid = _this.attr('pid');
					var userToken = localStorage.getItem("userTonken");
					var action = 'sentiment/toDesc.do?userToken='+userToken +'&pid='+pid;
					base.getAction(action);
					
				})
			});*/
			$('body').delegate('.sentimentList>ul>li', 'click', function(){
				
				var xKey = "_";
				var xkeyWord = $.trim($('#search').val());
				
				var s = xkeyWord.split(" ");
				var ss = "";
				for(var i = 0; i<s.length; i++){
					
					if (s[i]){
						ss = ss + s[i] + "_";
					}
				}
				xKey =  xKey + ss 
				
				var _this = $(this);
				var pid = _this.attr('pid');
				var userToken = localStorage.getItem("userTonken");
				var action = 'sentiment/toDesc.do?userToken='+userToken +'&pid='+pid +"&xKey=" + xKey;
				base.getAction(action);
			});
		}
	}
		
}

/** 舆情详情页面*/
vrv.sentiment.desc = {
		
	init: function(){
		this.btn.init();
	},
	
	
	
	page:{
		init: function(){
			
		}
	},
	
	btn: {
		init: function(){
		}
	}
		
}


/** 舆情趋势图页面*/
vrv.sentiment.countChat = {
		
	init: function(){
		this.btn.init();
		this.page.init();
	},
	
/*	htmlTmep:{
		popDiv:'<div style="
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
"></div>'
		
	}*/
	
	needRefresh : false,
	
	chatData:{
		
		dataObj:{
			legend: {
				data: ['舆情总量', '正面舆情', '负面舆情']
			},
			grid: {
				x: 48,
				x2: 10,
				y: 40,
				y2: 25
			},
			toolbox: {
				show: false
			},
			calculable: false,
			xAxis: [{
				type: 'category',
				data: ["09", "00", "11", "10", "13", "04", "12", "03", "15", "02", "14", "01", "08", "07", "06", "05"]
			}],
			yAxis: [{
				type: 'value',
				splitArea: {
					show: true
				}
				/* axisLabel : {
		                formatter: '{value}'/100 + ' °C'
		            }*/
			}],
			series: [
			{
				name: '舆情总量',
				type: 'line',
				data: [300, 352, 375, 320, 412, 413, 691, 420, 511, 719, 594, 553,132,321,154,123]
			},
			{
				name: '正面舆情',
				type: 'line',
				data: [2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3,70,85,21,44]
			}, {
				name: '负面舆情',
				type: 'line',
				data: [2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3,12,45,78,66]
			}]
			
		},
		
		getData: function(){
			return this.dataObj;
		},
		
		setDate: function(opt){
			this.dataObj.xAxis[0].data = opt.xAxisData;
			this.dataObj.series = opt.series;
			this.dataObj.legend.data = opt.name;
		},
		
		handleDate:function(opt){
			var timeMap = opt.timeMap;
			var nameArray = new Array();
			// 设置时间
			var timeArray = new Array(); 
			$.each(opt.timeMap, function(i,v){
			   if (v.hour){
			       timeArray.push(v.hour);
			    }else{
			       timeArray.push(v.moon + '-' + v.day);
			    }
			});
			
			$.each(opt.series, function(i,v){
				v.type='line';
				v.name=messages[v.name];
				nameArray.push(v.name)
			   
			});
			
			vrv.sentiment.countChat.chatData.setDate({
				xAxisData:timeArray,
				series:opt.series,
				name:nameArray
			});
		}
		
	},
	
	comFn:{
		showNav:function(id){
			$('.nav_btn').hide();
			$('.nav_btn#'+id).show();
		},
		
		byId: function(id) {
			return $('#'+id).get(0);
		},
		
		setClickFlag:function($obj){
			$('#day_m,#week_m,#moon_m').find('li').removeClass('aivity');
			$obj.addClass('aivity');
		},
		
		getClickFlag:function($obj){
			
		}
		
		
		
	},
	
	chatFn:{
	   myChart:null,
	   
	   divName:'lineChart',
	   
	   init: function(divName){
		   this.divName = divName || 'lineChart'
		   
		   vrv.sentiment.countChat.chatFn.myChart = echarts.init(vrv.sentiment.countChat.comFn.byId( vrv.sentiment.countChat.chatFn.divName));
		   vrv.sentiment.countChat.chatFn.myChart.setOption(vrv.sentiment.countChat.chatData.getData());
		   
	   },
		
	   refresh:function(isBtnRefresh){
		    if (isBtnRefresh) {
		    	vrv.sentiment.countChat.needRefresh = true;
		        this.focusGraphic();
		        return;
		    }
		    vrv.sentiment.countChat.needRefresh = false;
		    if (vrv.sentiment.countChat.chatFn.myChart && vrv.sentiment.countChat.chatFn.myChart.dispose) {
		    	vrv.sentiment.countChat.chatFn.myChart.dispose();
		    }
		    vrv.sentiment.countChat.chatFn.myChart = echarts.init(vrv.sentiment.countChat.comFn.byId( vrv.sentiment.countChat.chatFn.divName));
		    vrv.sentiment.countChat.chatFn.myChart.setOption(vrv.sentiment.countChat.chatData.getData(), true)
		},
		
		focusGraphic:function () {
		    if (vrv.sentiment.countChat.needRefresh) {
		    	vrv.sentiment.countChat.chatFn.myChart.showLoading();
		        setTimeout(vrv.sentiment.countChat.chatFn.refresh, 1000);
		    }
		}
		
	},
	
	page:{
		init: function(){
			this.initNav();
			this.initTime();
			this.initChat();
		},
		
		initChat: function(){
			
			var action="sentiment/getChat.do";
			// 获取今天的时间
			var time = new MrYangUtil();
			var startTime = time.getToday() + ' 00:00:00';
			var endTime = new Date().Format("yyyy-MM-dd hh:mm:ss");
			var userToken = localStorage.getItem("userTonken");
			vrv.sentiment.countChat.comFn.setClickFlag($('#today'));
			var data = {
				userToken:userToken,
				endTime:endTime,
				startTime:startTime
			}
			
			base.AJAX_POST(action, data, 'json', function(o){
				vrv.sentiment.countChat.chatData.handleDate(o);
				vrv.sentiment.countChat.chatFn.init();
			});
			
		},
		
		initNav:function(){
			var id = $('.nav_select_btn>.aivity').attr('id');
			vrv.sentiment.countChat.comFn.showNav(id);
		},
		initTime:function(){
			var currYear = (new Date()).getFullYear();	
			var opt={};
			opt.date = {preset : 'date'};
			//opt.datetime = { preset : 'datetime', minDate: new Date(2012,3,10,9,22), maxDate: new Date(2014,7,30,15,44), stepMinute: 5  };
			opt.datetime = {preset : 'datetime'};
			opt.time = {preset : 'time'};
			opt.my_default = {
				theme: 'android-ics light', //皮肤样式
		        display: 'modal', //显示方式 
		        mode: 'scroller', //日期选择模式
				lang:'zh',
		        startYear:currYear - 10, //开始年份
		        endYear:currYear //结束年份
			};

			 $('#startTime,#endTime').val('').scroller('destroy').scroller($.extend(opt['date'], opt['my_default']));
		}
	},
	
	btn: {
		init: function(){
			this.selectNavBtn();
			this.dayBtn.init();
			this.weekBtn.init();
			this.moonBtn.init();
			this.customBtn();
			
		},
		
		dayBtn: {
			init:function(){
				this.prevDay();
				this.today();
			},
			
			
			prevDay:function(){
				
				$('#prevDay').click(function(){
					
					var $this = $(this);
				    
					if($this.attr('class')=='aivity'){
				    	return;
				    }
					
				    vrv.sentiment.countChat.comFn.setClickFlag($this);
					
					// 获取昨天的日期
					var timeUtil = new MrYangUtil();
					var prevDay = timeUtil.getPreviousDay();
					
					var startTime = prevDay + ' 00:00:00';
					var endTime =  prevDay + ' 23:59:59';
					var action="sentiment/getChat.do";
					
					var userToken = localStorage.getItem("userTonken");
					var data = {
							userToken:userToken,
							endTime:endTime,
							startTime:startTime
						}
					
					base.AJAX_POST(action, data, 'json', function(o){
						vrv.sentiment.countChat.chatData.handleDate(o);
						vrv.sentiment.countChat.chatFn.refresh(true);
					});
				})
				
			},
			
			today:function(){
				$('#today').click(function(){
				
					var $this = $(this);
				    
					if($this.attr('class')=='aivity'){
				    	return;
				    }
					
					
					
					var action="sentiment/getChat.do";
					// 获取今天的时间
					var time = new MrYangUtil();
					var startTime = time.getToday() + ' 00:00:00';
					var endTime = new Date().Format("yyyy-MM-dd hh:mm:ss");
					vrv.sentiment.countChat.comFn.setClickFlag($('#today'));
					var userToken = localStorage.getItem("userTonken");
					var data = {
							userToken:userToken,
							endTime:endTime,
							startTime:startTime
						}
					
					base.AJAX_POST(action, data, 'json', function(o){
						vrv.sentiment.countChat.chatData.handleDate(o);
						vrv.sentiment.countChat.chatFn.refresh(true);
					});
				})
			}
			
		},
		
		weekBtn:{
			init:function(){
				this.prevWeek();
				this.thisWeek();
			},
			prevWeek:function(){
				$('#prevWeek').click(function(){
					var $this = $(this);
				    
					if($this.attr('class')=='aivity'){
				    	return;
				    }
					
					var action="sentiment/getChat.do";
					// 获取上周的时间
					var time = new MrYangUtil();
					
					var prevWeek = time.getPreviousWeek();
					var startTime = prevWeek[0] + ' 00:00:00';
					var endTime = prevWeek[1] + ' 23:59:59';
					
					vrv.sentiment.countChat.comFn.setClickFlag($this);
					var userToken = localStorage.getItem("userTonken");
					var data = {
							userToken:userToken,
							endTime:endTime,
							startTime:startTime
						}
					
					base.AJAX_POST(action, data, 'json', function(o){
						vrv.sentiment.countChat.chatData.handleDate(o);
						vrv.sentiment.countChat.chatFn.refresh(true);
					});
				});
			},
			
			thisWeek:function(){
				
				$('#thisWeek').click(function(){
					var $this = $(this);
				    
					if($this.attr('class')=='aivity'){
				    	return;
				    }
					
					var action="sentiment/getChat.do";
					// 获取今天的时间
					var time = new MrYangUtil();
					var startTime = time.getCurrentWeek()[0] + ' 00:00:00';
					var endTime = new Date().Format("yyyy-MM-dd hh:mm:ss");
					
					vrv.sentiment.countChat.comFn.setClickFlag($this);
					var userToken = localStorage.getItem("userTonken");
					var data = {
							userToken:userToken,
							endTime:endTime,
							startTime:startTime
						}
					
					base.AJAX_POST(action, data, 'json', function(o){
						vrv.sentiment.countChat.chatData.handleDate(o);
						vrv.sentiment.countChat.chatFn.refresh(true);
					});
				})
			}
		},
		
		moonBtn:{
			init:function(){
				this.prevMoon();
				this.thisMoon();
			},
			prevMoon:function(){
				$('#prevMoon').click(function(){
					var $this = $(this);
				    
					if($this.attr('class')=='aivity'){
				    	return;
				    }
					
					var action="sentiment/getChat.do";
					// 获取今天的时间
					var time = new MrYangUtil();

					var prevMoon = time.getPreviousMonth();
					var startTime = prevMoon[0] + ' 00:00:00';
					var endTime = prevMoon[1] + ' 23:59:59';
					
					vrv.sentiment.countChat.comFn.setClickFlag($this);
					var userToken = localStorage.getItem("userTonken");
					var data = {
							userToken:userToken,
							endTime:endTime,
							startTime:startTime
						}
					
					base.AJAX_POST(action, data, 'json', function(o){
						vrv.sentiment.countChat.chatData.handleDate(o);
						vrv.sentiment.countChat.chatFn.refresh(true);
					});
					
				});
			},
			
			thisMoon:function(){
				$('#thisMoon').click(function(){
					var $this = $(this);
				    
					if($this.attr('class')=='aivity'){
				    	return;
				    }
					
					var action="sentiment/getChat.do";
					// 获取今天的时间
					var time = new MrYangUtil();
					var startTime = time.getCurrentMonth()[0] + ' 00:00:00';
					var endTime = new Date().Format("yyyy-MM-dd hh:mm:ss");
					
					vrv.sentiment.countChat.comFn.setClickFlag($this);
					var userToken = localStorage.getItem("userTonken");
					var data = {
							userToken:userToken,
							endTime:endTime,
							startTime:startTime
						}
					
					base.AJAX_POST(action, data, 'json', function(o){
						vrv.sentiment.countChat.chatData.handleDate(o);
						vrv.sentiment.countChat.chatFn.refresh(true);
					});
				})
			}
		},
		
		customBtn:function(){
			$('.confirm_w').click(function(){
				
				var action="sentiment/getChat.do";
				// 获取今天的时间
				var time = new MrYangUtil();
				var startTime = $('#startTime').val();
				var endTime = $('#endTime').val();
				
				if(!startTime || !endTime){
					Message.showMessage({
						text: messages.validDateNull,
					});
					return;
				}
				
				
				if(time.string2Date(startTime) > time.string2Date(endTime)){
					Message.showMessage({
						text: messages.validDateBig,
					});
					return;
				}
				
			    //vrv.sentiment.countChat.comFn.setClickFlag($this);
				var userToken = localStorage.getItem("userTonken");
				var data = {
					userToken:userToken,
					endTime:endTime + '  23:59:59',
					startTime:startTime + ' 00:00:00'
				}
				
				base.AJAX_POST(action, data, 'json', function(o){
					vrv.sentiment.countChat.chatData.handleDate(o);
					vrv.sentiment.countChat.chatFn.refresh(true);
				});
			});
		},
	
		selectNavBtn:function(){
			$('.nav_select_btn>li').click(function(){
				var $this = $(this);
				if($this.attr('class')=='aivity'){
			    	return;
			    }
				$('.nav_select_btn>li').removeClass("aivity");
				$this.addClass('aivity');
				var id = $this.attr('id');
				var hald = $this.attr('hald');
				vrv.sentiment.countChat.comFn.showNav(id);
				$('.countChat>h5').empty().text(messages[id]);
				$('#' + hald).click();
				
			});
		}
	}
}

$(function(){
	$('#toIndex').click(function(){
		var userToken = localStorage.getItem("userTonken");
		var action = 'attention/index.do?userToken='+userToken;
		base.getAction(action);
	})
	
})
